import requests
import json
from lxml import etree
import time
import csv
import os

def mymkdir(filepath):
    print(type(filepath))
    filepath = filepath.strip()
    filepath = filepath.rstrip("\\")
    isExists = os.path.exists(filepath)
    if isExists:
        print(filepath + ' 目录已存在')
        return False
    else:
        os.makedirs(filepath)
        print('创建成功')
        return True

if __name__=='__main__':
    print('开始')
    timepath=time.strftime('%Y/%m/%d/')
    timepath=timepath+'wangyi/'
    print(type(timepath))
    print(timepath)
    mymkdir(timepath)
    datapath=timepath+'data.csv'
    # 创建或打开文件
    csvfile = open(datapath, mode='w', newline='')
    # 标题列表
    fieldnames = ['title', 'content', 'url']
    # 创建 DictWriter 对象
    write = csv.DictWriter(csvfile, fieldnames=fieldnames)
    # 写入表头
    write.writeheader()
    # 写入数据
    write.writerow({'title': 80, 'content': 90, 'url': 20})


